cmake_minimum_required(VERSION 3.12)
project(test_vision)

file(GLOB ${PROJECT_NAME}_SOURCES
    "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp"
)

if(BUILD_NN AND BUILD_EKF)
    add_executable(${PROJECT_NAME} ${${PROJECT_NAME}_SOURCES})

    target_link_libraries(${PROJECT_NAME} PRIVATE
        object
        detector
        predictor
        classifier
        compensator
        nvinfer
        nvonnxparser
        cudart
        ${CERES_LIBRARIES} 
        gtest
        gtest_main
    )

    if (CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64")
        target_include_directories(${PROJECT_NAME} PUBLIC /usr/local/cuda/targets/aarch64-linux/include)
        target_link_directories(${PROJECT_NAME} PUBLIC /usr/local/cuda/targets/aarch64-linux/lib)
    else()
        target_include_directories(${PROJECT_NAME} PUBLIC /usr/local/cuda/include)
        target_link_directories(${PROJECT_NAME} PUBLIC /usr/local/cuda/lib64)
    endif()

    target_include_directories(${PROJECT_NAME} PUBLIC
        ${CMAKE_CURRENT_SOURCE_DIR}
        ${EIGEN3_INCLUDE_DIR}
        ${CERES_INCLUDE_DIRS}
        $<TARGET_PROPERTY:object,INTERFACE_INCLUDE_DIRECTORIES>
        $<TARGET_PROPERTY:detector,INTERFACE_INCLUDE_DIRECTORIES>
        $<TARGET_PROPERTY:predictor,INTERFACE_INCLUDE_DIRECTORIES>
        $<TARGET_PROPERTY:classifier,INTERFACE_INCLUDE_DIRECTORIES>
        $<TARGET_PROPERTY:compensator,INTERFACE_INCLUDE_DIRECTORIES>
    )   

elseif(BUILD_NN AND NOT BUILD_EKF)

    list(FILTER ${PROJECT_NAME}_SOURCES EXCLUDE REGEX "ekf.*$")

    add_executable(${PROJECT_NAME} ${${PROJECT_NAME}_SOURCES})

    target_link_libraries(${PROJECT_NAME} PRIVATE
        object
        detector
        predictor
        classifier
        compensator
        nvinfer
        nvonnxparser
        cudart
        gtest
        gtest_main
    )
    
    if (CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64")
        target_include_directories(${PROJECT_NAME} PUBLIC /usr/local/cuda/targets/aarch64-linux/include)
        target_link_directories(${PROJECT_NAME} PUBLIC /usr/local/cuda/targets/aarch64-linux/lib)
    else()
        target_include_directories(${PROJECT_NAME} PUBLIC /usr/local/cuda/include)
        target_link_directories(${PROJECT_NAME} PUBLIC /usr/local/cuda/lib64)
    endif()

    target_include_directories(${PROJECT_NAME} PUBLIC
        ${CMAKE_CURRENT_SOURCE_DIR}
        $<TARGET_PROPERTY:object,INTERFACE_INCLUDE_DIRECTORIES>
        $<TARGET_PROPERTY:detector,INTERFACE_INCLUDE_DIRECTORIES>
        $<TARGET_PROPERTY:predictor,INTERFACE_INCLUDE_DIRECTORIES>
        $<TARGET_PROPERTY:classifier,INTERFACE_INCLUDE_DIRECTORIES>
        $<TARGET_PROPERTY:compensator,INTERFACE_INCLUDE_DIRECTORIES>
    )

elseif(NOT BUILD_NN AND BUILD_EKF)

    list(FILTER ${PROJECT_NAME}_SOURCES EXCLUDE REGEX "trt.*$")
    list(FILTER ${PROJECT_NAME}_SOURCES EXCLUDE REGEX "radar.*$")

    add_executable(${PROJECT_NAME} ${${PROJECT_NAME}_SOURCES})

    target_link_libraries(${PROJECT_NAME} PRIVATE
        object
        detector
        predictor
        classifier
        compensator
        ${CERES_LIBRARIES} 
        gtest
        gtest_main
    )

    target_include_directories(${PROJECT_NAME} PUBLIC
        ${CMAKE_CURRENT_SOURCE_DIR}
        ${EIGEN3_INCLUDE_DIR}
        ${CERES_INCLUDE_DIRS}
        $<TARGET_PROPERTY:object,INTERFACE_INCLUDE_DIRECTORIES>
        $<TARGET_PROPERTY:detector,INTERFACE_INCLUDE_DIRECTORIES>
        $<TARGET_PROPERTY:predictor,INTERFACE_INCLUDE_DIRECTORIES>
        $<TARGET_PROPERTY:classifier,INTERFACE_INCLUDE_DIRECTORIES>
        $<TARGET_PROPERTY:compensator,INTERFACE_INCLUDE_DIRECTORIES>
    )   

elseif(NOT BUILD_NN AND NOT BUILD_EKF)

    list(FILTER ${PROJECT_NAME}_SOURCES EXCLUDE REGEX "ekf.*$")
    list(FILTER ${PROJECT_NAME}_SOURCES EXCLUDE REGEX "trt.*$")
    list(FILTER ${PROJECT_NAME}_SOURCES EXCLUDE REGEX "radar.*$")

    add_executable(${PROJECT_NAME} ${${PROJECT_NAME}_SOURCES})

    target_link_libraries(${PROJECT_NAME} PRIVATE
        object
        detector
        predictor
        classifier
        compensator
        gtest
        gtest_main
    )
        
    target_include_directories(${PROJECT_NAME} PUBLIC
        ${CMAKE_CURRENT_SOURCE_DIR}
        $<TARGET_PROPERTY:object,INTERFACE_INCLUDE_DIRECTORIES>
        $<TARGET_PROPERTY:detector,INTERFACE_INCLUDE_DIRECTORIES>
        $<TARGET_PROPERTY:predictor,INTERFACE_INCLUDE_DIRECTORIES>
        $<TARGET_PROPERTY:classifier,INTERFACE_INCLUDE_DIRECTORIES>
        $<TARGET_PROPERTY:compensator,INTERFACE_INCLUDE_DIRECTORIES>
    )

endif()

add_test(test_vision test_vision)
